package fr.resasante.spring3.controller;

import java.security.Principal;
import java.util.Collection;
import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import fr.resasante.spring3.controller.common.ControllerAbstract;

/**
 * Controller for displaying the homepage
 * 
 * @author GEFFROY-DE-VILLEBLAN
 * 
 */
@Controller
public class HomeController extends ControllerAbstract {
	/**
	 * Displays the home page
	 * 
	 * @return The view for the home page
	 */
	@RequestMapping("/home")
	public ModelAndView showHome(HttpServletRequest request, Principal principal, Locale locale) {
		final ModelAndView modelAndView = new ModelAndView("home");
		final String message = messageSource.getMessage("title.home", null, locale);
		modelAndView.addObject("pageTitle", message);
		/*Authentication auth = (Authentication) principal;
		Collection<GrantedAuthority> auts = (Collection<GrantedAuthority>) auth
				.getAuthorities();
		for (GrantedAuthority aut : auts) {
			System.out.println(aut.getAuthority());
		}*/
		return modelAndView;
	}
}
